package com.koron.order.linepatrol.satellite.service.impl;


import cn.hutool.core.collection.CollUtil;
import com.github.pagehelper.PageInfo;
import com.koron.bean.query.PageQuery;
import com.koron.order.linepatrol.satellite.bean.po.LinePatrolMonitor;
import com.koron.order.linepatrol.satellite.bean.query.LinePatrolMonitorQuery;
import com.koron.order.linepatrol.satellite.mapper.LinePatrolMonitorMapper;
import com.koron.order.linepatrol.satellite.service.LinePatrolMonitorService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 卫星监测风险工单(LinePatrolMonitor)表服务实现类
 *
 * @author jzp
 * @since 2023-02-08 16:47:14
 */
@Service
public class LinePatrolMonitorServiceImpl implements LinePatrolMonitorService {

    /**
     * 通过ID查询单条数据
     *
     */
    @Override
    @TaskAnnotation("getById")
    public LinePatrolMonitor getById(SessionFactory factory, String id) {
        LinePatrolMonitorMapper mapper = factory.getMapper(LinePatrolMonitorMapper.class);
        return mapper.selectById(id);
    }

    /**
     * 查询所有数据
     *
     */
    @Override
    @TaskAnnotation("list")
    public List<LinePatrolMonitor> list(SessionFactory factory, LinePatrolMonitorQuery query) {
        LinePatrolMonitorMapper mapper = factory.getMapper(LinePatrolMonitorMapper.class);
        return mapper.selectList(query);
    }

    @Override
    @TaskAnnotation("page")
    public PageInfo<LinePatrolMonitor> page(SessionFactory factory, PageQuery pageQuery, LinePatrolMonitorQuery query) {
        return LinePatrolMonitorService.super.page(factory, pageQuery, query);
    }

    /**
     * 新增数据
     *
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, LinePatrolMonitor linePatrolMonitor) {
        LinePatrolMonitorMapper mapper = factory.getMapper(LinePatrolMonitorMapper.class);
        return mapper.insertOrUpdate(linePatrolMonitor) > 0;
    }

    @Override
    @TaskAnnotation("saveBatch")
    public boolean saveBatch(SessionFactory factory, List<LinePatrolMonitor> linePatrolMonitorList) {
        if (CollUtil.isEmpty(linePatrolMonitorList)) {
            return false;
        }
        LinePatrolMonitorMapper mapper = factory.getMapper(LinePatrolMonitorMapper.class);
        return mapper.insertOrUpdateBatch(linePatrolMonitorList) > 0;
    }

    /**
     * 修改数据
     *
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, LinePatrolMonitor linePatrolMonitor) {
        LinePatrolMonitorMapper mapper = factory.getMapper(LinePatrolMonitorMapper.class);
        return mapper.update(linePatrolMonitor) > 0;
    }

    /**
     * 通过主键删除数据
     *
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        LinePatrolMonitorMapper mapper = factory.getMapper(LinePatrolMonitorMapper.class);
        return mapper.hidden(id) > 0;
    }
}
